package com.renbang.action.devoloper;



import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.renbang.model.crawl.TaskJob;
import com.renbang.utils.quartz.QuartzSchedule;
@Controller
@RequestMapping(value = "developer/quartz")
public class QuartzAction {
	QuartzSchedule quartzSchedule = new QuartzSchedule();
	@RequestMapping(value = "/startJob")
	public @ResponseBody   String  start(HttpServletRequest request) {
		try {
			 TaskJob taskJob = new TaskJob();
		     taskJob.setJobName("job1");
		     taskJob.setGropName("group1");
		     taskJob.setTriggerName("trigger1");
		     taskJob.setCron("0/3 * * * * ?");
		     quartzSchedule.startJob(taskJob);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "startJob";
	}
	
	@RequestMapping(value = "/modifyTrigger")
	public @ResponseBody String modifyTrigger(HttpServletRequest request) {
		try {
			TaskJob taskJob = new TaskJob();
		     taskJob.setJobName("job1");
		     taskJob.setGropName("group1");
		     taskJob.setTriggerName("trigger1");
		     taskJob.setCron("0/3 * * * * ?");
			quartzSchedule.modifyTrigger(taskJob);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "modifyTrigger";
	}
	@RequestMapping(value = "/pauseJob")
	public @ResponseBody String pauseJob(HttpServletRequest request) {
		try {
			TaskJob taskJob = new TaskJob();
		     taskJob.setJobName("job1");
		     taskJob.setGropName("group1");
		     taskJob.setTriggerName("trigger1");
		     taskJob.setCron("0/3 * * * * ?");
			quartzSchedule.pauseJob(taskJob);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "pauseJob";
	}
	@RequestMapping(value = "/resumeJob")
	public @ResponseBody String resumeJob(HttpServletRequest request) {
		try {
			TaskJob taskJob = new TaskJob();
		     taskJob.setJobName("job1");
		     taskJob.setGropName("group1");
		     taskJob.setTriggerName("trigger1");
		     taskJob.setCron("0/3 * * * * ?");
			quartzSchedule.resumeJob(taskJob);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "resumeJob";
	}
	@RequestMapping(value = "/removeJob")
	public @ResponseBody String removeJob(HttpServletRequest request) {
		try {
			TaskJob taskJob = new TaskJob();
		     taskJob.setJobName("job1");
		     taskJob.setGropName("group1");
		     taskJob.setTriggerName("trigger1");
		     taskJob.setCron("0/3 * * * * ?");
			quartzSchedule.removeJob(taskJob);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "removeJob";
	}
	@RequestMapping(value = "/shutdownScheduler")
	public @ResponseBody String shutdownScheduler(HttpServletRequest request) {
		try {
			quartzSchedule.shutdownScheduler();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "shutdownScheduler";
	}
	
}
